home *** CD-ROM | disk | FTP | other *** search
/ Aminet 28 / Aminet 28 (1998)(GTI - Schatztruhe)[!][Dec 1998].iso / Aminet / dev / src / GLperf3.12-src.lha / GLperf / LineStrp.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-08-01  |  6.0 KB  |  184 lines

  1. /*
  2. //   (C) COPYRIGHT International Business Machines Corp. 1993
  3. //   All Rights Reserved
  4. //   Licensed Materials - Property of IBM
  5. //   US Government Users Restricted Rights - Use, duplication or
  6. //   disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  7. //
  8.  
  9. //
  10. // Permission to use, copy, modify, and distribute this software and its
  11. // documentation for any purpose and without fee is hereby granted, provided
  12. // that the above copyright notice appear in all copies and that both that
  13. // copyright notice and this permission notice appear in supporting
  14. // documentation, and that the name of I.B.M. not be used in advertising
  15. // or publicity pertaining to distribution of the software without specific,
  16. // written prior permission. I.B.M. makes no representations about the
  17. // suitability of this software for any purpose.  It is provided "as is"
  18. // without express or implied warranty.
  19. //
  20. // I.B.M. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL
  21. // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL I.B.M.
  22. // BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  23. // WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
  24. // OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
  25. // CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  26. //
  27. // Author:  John Spitzer, IBM AWS Graphics Systems (Austin)
  28. //
  29. */
  30.  
  31. #include <math.h>
  32. #include "LineStrp.h"
  33.  
  34. #undef offset
  35. #define offset(v) offsetof(LineStrip,v)
  36.  
  37. static InfoItem LineStripInfo[] = {
  38. #define INC_REASON INFO_ITEM_ARRAY
  39. #include "LineStrp.h"
  40. #undef INC_REASON
  41. };
  42. #include <malloc.h>
  43.  
  44. LineStripPtr new_LineStrip()
  45. {
  46.     LineStripPtr this = (LineStripPtr)malloc(sizeof(LineStrip));
  47.     CheckMalloc(this);
  48.     new_Linear((LinearPtr)this);
  49.     SetDefaults((TestPtr)this, LineStripInfo);
  50.     this->testType = LineStripTest;
  51.     this->primitiveType = GL_LINE_STRIP;
  52.     this->vertsPerFacet = 1;
  53.     this->usecPixelPrint = " microseconds per pixel with Line Strip";
  54.     this->ratePixelPrint = " pixels per second with Line Strip";
  55.     this->usecPrint = " microseconds per Line in a Line Strip";
  56.     this->ratePrint = " Lines per second in a Line Strip";
  57.     /* Set virtual functions */
  58.     this->delete = delete_LineStrip;
  59.     this->Layout = LineStrip__Layout;
  60.     this->Copy = LineStrip__Copy;
  61.     return this;
  62. }
  63.  
  64. void delete_LineStrip(TestPtr thisTest)
  65. {
  66.     LineStripPtr this = (LineStripPtr)thisTest;
  67.     delete_Linear(thisTest);
  68. }
  69.  
  70. TestPtr LineStrip__Copy(TestPtr thisTest)
  71. {
  72.     LineStripPtr this = (LineStripPtr)thisTest;
  73.     LineStripPtr newLineStrip = new_LineStrip();
  74.     FreeStrings((TestPtr)newLineStrip);
  75.     *newLineStrip = *this;
  76.     CopyStrings((TestPtr)newLineStrip, (TestPtr)this);
  77.     return (TestPtr)newLineStrip;
  78. }
  79.  
  80. void LineStrip__Layout(VertexPtr thisVertex)
  81. {
  82.     LineStripPtr this = (LineStripPtr)thisVertex;
  83.     int windowDim = min(this->environ.windowWidth, this->environ.windowHeight);
  84.     GLfloat *newTraversalData;
  85.     GLfloat *dst, *src;
  86.     GLfloat ndcLength;
  87.     int i, j;
  88.     GLfloat x, y;
  89.  
  90.     /* Use orientation to choose layout */
  91.     this->vertsPerBgnEnd = this->objsPerBgnEnd * this->vertsPerFacet + 1;
  92.     this->facetsPerBgnEnd = this->vertsPerBgnEnd/this->vertsPerFacet;
  93.  
  94.     /* Allocate necessary data */
  95.     newTraversalData = (GLfloat*)malloc(this->numBgnEnds * this->vertsPerBgnEnd * 2 * sizeof(GLfloat));
  96.     CheckMalloc(newTraversalData);
  97.     dst = newTraversalData;
  98.  
  99.     ndcLength = this->size/(GLfloat)windowDim*2.0;
  100.     
  101.     if (this->orientation == Random) {
  102.         GLfloat random_angle;
  103.         const double pi=3.141592654;
  104.         GLfloat new_x, new_y;
  105.     GLfloat edgePad = (1. + this->lineWidth/2. + (this->antiAlias!=Off))/ 
  106.                           (float)windowDim;
  107.     mysrand(15000);
  108.  
  109.         /* Use Vertex__Layout to get line starts */
  110.         this->layoutPoints = this->numBgnEnds;
  111.         this->layoutPadding = ndcLength;
  112.         this->layoutPadding += edgePad;
  113.     if (this->size > (float)windowDim/2.) {
  114.         /* If lines are long, position begining points at edge */
  115.         this->acceptObjs = 0.0;
  116.         this->rejectObjs = 0.0;
  117.         this->clipObjs = 1.0;
  118.     } else {
  119.         this->acceptObjs = 1.0;
  120.         this->rejectObjs = 0.0;
  121.         this->clipObjs = 0.0;
  122.     }
  123.         Vertex__Layout(thisVertex);
  124.     /* Restore state */
  125.     this->acceptObjs = 1.0;
  126.     this->rejectObjs = 0.0;
  127.     this->clipObjs = 0.0;
  128.  
  129.         src = this->traversalData;
  130.         dst = newTraversalData;
  131.  
  132.         for (i=0; i<this->numBgnEnds; i++) {
  133.             x = *src++;
  134.             y = *src++;
  135.             for (j=0; j<this->vertsPerBgnEnd; j++) {
  136.                 *dst++ = x;
  137.                 *dst++ = y;
  138.                 do {
  139.             random_angle = 2.0*pi*(double)myrand()/(double)MY_RAND_MAX;
  140.             new_x = x + ndcLength * cos(random_angle);
  141.             new_y = y + ndcLength * sin(random_angle);
  142.                 } while (new_x <= -1.0 + edgePad || 1.0 - edgePad <= new_x || 
  143.                          new_y <= -1.0 + edgePad || 1.0 - edgePad <= new_y);
  144.         x = new_x;
  145.         y = new_y;
  146.             }
  147.         }
  148.         free(this->traversalData);
  149.     } else {
  150.         enum {Horz, Vert} direction;
  151.         GLfloat horz, vert;
  152.         int bounced = True;
  153.         int row = 0;
  154.         for (i=0; i<this->numBgnEnds; i++) {
  155.             if (bounced) {
  156.                 x = -1.0;
  157.                 y = fmod(row * ndcLength, 2.0) - 1.0;
  158.                 horz = ndcLength;
  159.                 vert = -ndcLength;
  160.                 direction = Horz;
  161.                 bounced = False;
  162.                 row+=2;
  163.             }
  164.             for (j=0; j<this->vertsPerBgnEnd; j++) {
  165.                 if (direction == Horz) {
  166.                     if (x+horz <= -1.0 || 1.0 <= x+horz) {
  167.                         horz *= -1.0;
  168.                         bounced = True;
  169.                     }
  170.                     x += horz;
  171.                     direction = Vert;
  172.                 } else {
  173.                     y += vert;
  174.                     vert *= -1.0;
  175.                     direction = Horz;
  176.                 }
  177.                 *dst++ = x;
  178.                 *dst++ = y;
  179.             }
  180.         }
  181.     }
  182.     this->traversalData = newTraversalData;
  183. }
  184.